package com.dc.service.impl;

import com.dc.base.model.BaseModel;
import com.dc.dao.UserDao;
import com.dc.dao.impl.UserDaoImpl;
import com.dc.service.UserService;

import java.util.List;

public class UserServiceImpl implements UserService {
    UserDao userDao=new UserDaoImpl();
    BaseModel baseModel=new BaseModel();
    @Override
    public BaseModel selectUser(Object[] parame) throws Exception {

        String sql="select * from t_user";
        List list=userDao.selectUser(sql,null);
        baseModel.setCode(1);
        baseModel.setMessage("查询成功");
        baseModel.setData(list);
        return baseModel;
    }

    @Override
    public BaseModel deleteUser(String id) throws Exception {
        String sql="delete from t_user where user_id in("+id+")";
        int remes=userDao.DeleteUser(sql);
        System.out.println(remes);
        if(remes>0){
            baseModel.setCode(1);

            baseModel.setMessage("删除成功");
            System.out.println("删除成功");
        }else {
            baseModel.setCode(0);
            baseModel.setMessage("删除失败");
            System.out.println("删除失败");
        }

        return baseModel;
    }

    @Override
    public BaseModel addUser(Object[] parame) throws Exception {

        String sql = "insert into t_user(user_name,user_trueName,user_cardId,user_email,user_telephone,user_qqId,user_pwd,regTime,question,answer,state) values(?,?,?,?,?,?,?,?,?,?,?)";
        int remes = userDao.addUser(sql, parame);
        if (remes==1){
            baseModel.setCode(1);
            baseModel.setMessage("新增成功");
        }else {
            baseModel.setCode(0);
            baseModel.setMessage("新增失败");

        }
        return  baseModel;
    }

    @Override
    public BaseModel updateUser(Object[] parame) throws Exception {
        String sql="update t_user set user_name=?,user_trueName=?,user_cardId=?,user_email=?,user_telephone=?,user_qqId=?,user_pwd=?,regTime=?,question=?,answer=?,state=? where user_id=?";
        int remes=userDao.updateUser(sql,parame);
        if (remes==1){
            baseModel.setCode(1);
            baseModel.setMessage("修改成功");
        }else{
            baseModel.setCode(0);
            baseModel.setMessage("修改失败");
        }
        return baseModel;
    }

    @Override
    public BaseModel selectUserid(int id) throws Exception {
        String  sql="select * from t_user where user_id="+id+"";
        List list=userDao.selectUserid(sql,null);
        baseModel.setCode(1);
        baseModel.setMessage("查询成功");
        baseModel.setData(list);
        return baseModel;
    }
}
